package com.spboot.user.service;

import javax.jms.Destination;

import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.spboot.user.entity.User;

@Service
public class UserService {

	@Autowired
	JmsTemplate jmsTemplate;

	// 注冊用戶
	public void register() {
		// 数据库
		User user = new User(1, "admin");
		
		Destination destination = new ActiveMQQueue("user_reg");
		// 发送消息 -- 发邮件
		jmsTemplate.convertAndSend(destination, JSON.toJSONString(user));
		
		// 发短信
		Destination destinationSms = new ActiveMQQueue("user_sms");
		jmsTemplate.convertAndSend(destinationSms, JSON.toJSONString(user));
	}
}
